﻿
using System.Data;

namespace WDCF
{
    /// <summary>
    /// Helper class for defining a condition
    /// </summary>
    public class Condition
    {
        /// <summary>
        /// Gets or sets the name of the property
        /// </summary>
        public string PropertyName { get; set; }
        
        /// <summary>
        /// Gets or sets the <see cref="StringOperator"/>
        /// </summary>
        public StringOperator StringOperator { get; set; }
        
        /// <summary>
        /// Gets or sets the <see cref="NumericOperator"/>
        /// </summary>
        public NumericOperator NumericOperator { get; set; }
        
        /// <summary>
        /// Gets or sets the value to which the property shall be compared
        /// </summary>
        public string CompareValue { get; set; }

        internal PropertyType PropertyType { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Condition"/> class.
        /// </summary>
        /// <param name="propertyName">The name of the property.</param>
        public Condition(string propertyName)
        {
            PropertyName = propertyName;
            PropertyType = PropertyType.Boolean;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Condition"/> class.
        /// </summary>
        /// <param name="column">A <see cref="DataColumn"/> whose values will be used for comparison.</param>
        public Condition(DataColumn column)
            :this(column.ColumnName)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Condition"/> class.
        /// </summary>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="numericOperator">The <see cref="NumericOperator"/> user for comparison.</param>
        /// <param name="compareValue">The value to which the property shall be compared</param>
        public Condition(string propertyName, NumericOperator numericOperator, string compareValue)
            :this(propertyName)
        {
            NumericOperator = numericOperator;
            CompareValue = compareValue;
            PropertyType = PropertyType.Number;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Condition"/> class.
        /// </summary>
        /// <param name="column">A <see cref="DataColumn"/> whose values will be used for comparison.</param>
        /// <param name="numericOperator">The <see cref="NumericOperator"/> user for comparison.</param>
        /// <param name="compareValue">The value to which the column values shall be compared.</param>
        public Condition(DataColumn column, NumericOperator numericOperator, string compareValue)
            :this(column.ColumnName, numericOperator, compareValue)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Condition"/> class.
        /// </summary>
        /// <param name="propertyName">The name of the property.</param>
        /// <param name="stringOperator">The <see cref="StringOperator"/> user for comparison.</param>
        /// <param name="compareValue">The value to which the property shall be compared</param>
        public Condition(string propertyName, StringOperator stringOperator, string compareValue):
            this(propertyName)
        {
            StringOperator = stringOperator;
            CompareValue = compareValue;
            PropertyType = PropertyType.String;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Condition"/> class.
        /// </summary>
        /// <param name="column">A <see cref="DataColumn"/> whose values will be used for comparison.</param>
        /// <param name="stringOperator">The <see cref="StringOperator"/> user for comparison.</param>
        /// <param name="compareValue">The value to which the column values shall be compared.</param>
        public Condition(DataColumn column, StringOperator stringOperator, string compareValue)
            : this(column.ColumnName, stringOperator, compareValue)
        {
        }
    }
}
